<template>
  <div>
    <el-dialog
      :title="this.$t('ExpressCargoManagementLang.trajectory_add')"
      :visible.sync="Visible"
      width="600px"
      :close-on-click-modal="false"
      @close="cancel"
    >
      <div class="midContant clearfix">
        <div class="dialogBox top">
          <div class="dialogBoxItem">
            <div style="width:49%;" class="dialogBoxItemRow">
              <div class="title">
                <div class="RequiredRowTip">*</div>
                {{$t('ExpressCargoManagementLang.trajectory_time')}}:
              </div>
              <div class="contant">
                <el-date-picker
                  ref="track_at"
                  class="Required" 
                  @blur="Blur('track_at')"
                  @focus="Focus('track_at')"
                  v-model="data.track_at"
                  value-format="timestamp"
                  type="datetime"
                  :placeholder="$t('common.select_plactholder')"
                >
                </el-date-picker>
              </div>
            </div>
            <div style="width:49%;" class="dialogBoxItemRow">
              <div class="title">
                <div class="RequiredRowTip">*</div>
                {{$t('ExpressCargoManagementLang.trajectory_text_zh')}}:
              </div>
              <div class="contant">
                <el-input
                  ref="desc"
                  @blur="handleBlur('desc',$event)"
                  @focus="handleFocus($event)"
                  class="Required"
                  :placeholder="$t('common.input_plactholder')"
                  v-model="data.desc"
                ></el-input>
              </div>
            </div>
          </div>
          <div class="dialogBoxItem">
            <div style="width:49%;" class="dialogBoxItemRow">
              <div class="title">
                <div class="RequiredRowTip">*</div>
                {{$t('ExpressCargoManagementLang.trajectory_text_en')}}:
              </div>
              <div class="contant">
                <el-input
                  ref="desc_en"
                  @blur="handleBlur('desc_en',$event)"
                  @focus="handleFocus($event)"
                  class="Required"
                  :placeholder="$t('common.input_plactholder')"
                  v-model="data.desc_en"
                ></el-input>
              </div>
            </div>
            <div style="width:49%;" class="dialogBoxItemRow">
              <div class="title">
                <div class="RequiredRowTip">*</div>
                {{$t('ExpressCargoManagementLang.trajectory_text_ru')}}:
              </div>
              <div class="contant">
                <el-input
                  ref="desc_ru"
                  @blur="handleBlur('desc_ru',$event)"
                  @focus="handleFocus($event)"
                  class="Required"
                  :placeholder="$t('common.input_plactholder')"
                  v-model="data.desc_ru"
                ></el-input>
              </div>
            </div>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirm" size="small"
          >{{$t('common.confirm')}}</el-button
        >
        <el-button  @click="cancel" size="small">{{$t('common.cancel')}}</el-button>
      </span>
      
    </el-dialog>
  </div>
</template>

<script>
export default {
  components: {},
  props: {
    // 接收绑定参数
    midHight: [Number,String],
  },
  data() {
    return {
      Visible: false,
      dataObj:{},
      data:{
        track_at:"",
        desc:"",
        desc_en:"",
        desc_ru:"",
      },
      confirmTrue:true,//确定按钮保护
    };
  },
  created() {
    
  },
  mounted() {
  },
  deactivated(){
    
  },
  watch: {
  },
  methods: {
   
    init(data) {
      this.dataObj=data
      this.data.track_at=new Date().getTime()
      this.Visible = true;
    },
    // 提交修改
    confirm() {
      //是否有空值必选项标识
      let type = true;
      //输入框判断是否有值
      if(!this.data.track_at){
        this.$refs.track_at.$el.childNodes[1].style.border='1px solid red'
        type=false
      }
      if(!this.data.desc){
        this.$refs.desc.$el.childNodes[1].style.border='1px solid red'
        type=false
      }
      if(!this.data.desc_en){
        this.$refs.desc_en.$el.childNodes[1].style.border='1px solid red'
        type=false
      }
      if(!this.data.desc_ru){
        this.$refs.desc_ru.$el.childNodes[1].style.border='1px solid red'
        type=false
      }
      if (type&&this.confirmTrue) {
        this.confirmTrue=false
        window.setTimeout(()=>{
          this.confirmTrue=true
        },1000)
        // let str=this.dataArr.map((obj)=>{return ""+obj.package_sn}).join(",")
        let params = new FormData();
        params.append("order_sn", this.dataObj.order_sn);
        params.append("track_at", this.data.track_at/1000);
        params.append("desc", this.data.desc);
        params.append("desc_en", this.data.desc_en);
        params.append("desc_ru", this.data.desc_ru);
        this.$postForm("addWaybillTrack", params).then((res) => {
          this.confirmTrue=true
          if(res.success){
            this.cancel()
            this.$message.success(res.msg);
            this.$emit("success");
          }
        });
      }
    },
    //取消修改
    cancel() {
      this.data={
        track_at:"",
        desc:"",
        desc_en:"",
        desc_ru:"",
      } 
      this.Visible = false;
      let dom = document.getElementsByClassName("el-input__inner");
      for (let i = 0; i < dom.length; i++) {
         dom[i].style.border = "1px solid #E0E3E9";
      }
    },
    //输入框、下拉框失去焦点边框变色
    handleBlur(name, event) {
      if (!this.data[name]&&this.data[name]!==0) {
        event.target.style.border = "1px solid red";
      }
    },
    //输入框、下拉框获取焦点边框变色
    handleFocus(event) {
      event.target.style.border = "1px solid #E0E3E9";
    },
    // 判断了时间组件内容是否有东西
    Focus(name) {
      let dom = this.$refs[name].$el.childNodes[1]
      dom.style.border = "1px solid #E0E3E9";
      
    },
    Blur(name) {
      let dom = this.$refs[name].$el.childNodes[1]
      if (!this.data[name]) {
        dom.style.border = "1px solid red";
      }
    },
  },
};
</script>

<style scoped lang="less" >
  .midContant {
    border: 0;
    width: 100%;
  }
  .dialogBox .dialogBoxItem .dialogBoxItemRow {
    width: 24%;
  }
</style>